import os
import shutil
import platform


if __name__ == '__main__':
    arch = platform.machine()
    dir_arch = {'aarch64': 'arm64', 'x86_64': 'x64', 'AMD64': 'x64'}
    docker_arch = {'aarch64': 'arm64', 'x86_64': 'amd64', 'AMD64': 'amd64'}
    os.system(
        "cd ascend-docker-image/ &&"
        "git clean -f -d &&"
        "git reset --hard HEAD^ &&"
        "git pull"
    )
    shutil.copyfile('libstdc++.so.6.0.24', "ascend-docker-image/Dockerfile/latest/common/ascendbase-train/centos7.6-%s/libstdc++.so.6.0.24" % dir_arch[arch])
    res = os.system(
        "cd ascend-docker-image/Dockerfile/latest/common/ascendbase-train/centos7.6-%s &&"
        "docker build -t ascendbase-train:centos7.6-%s ." % (dir_arch[arch], docker_arch[arch])
    )
    if res != 0:
        print("build ascendbase-train:centos7.6-%s return non zero" % dir_arch[arch])

    #  build openeuler
    shutil.copyfile('libstdc++.so.6.0.24', "ascend-docker-image/Dockerfile/latest/common/ascendbase-train/openeuler20.03-%s/libstdc++.so.6.0.24" % dir_arch[arch])
    res = os.system(
        "cd ascend-docker-image/Dockerfile/latest/common/ascendbase-train/openeuler20.03-%s &&"
        "docker build -t ascendbase-train:openeuler20.03-%s ." % (dir_arch[arch], docker_arch[arch])
    )
    if res != 0:
        print("build ascendbase-train:openeuler20.03-%s return non zero" % dir_arch[arch])

